package com.jiutong.meipenggang.views.dialog;

import android.app.FragmentManager;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;

import com.jiutong.meipenggang.R;
import com.jiutong.meipenggang.base.AppManager;

/**
 * 作用:
 * Created by 78 on 2017/8/12.
 */

public class CommonDialog {

    private BaseDialog dialog;
    private Context context;
    private FragmentManager fragmentManager;
    private Class<?> mClass;
    private String contentText;
    private String okText;

    public String getCancelText() {
        return cancelText;
    }

    public void setCancelText(String cancelText) {
        this.cancelText = cancelText;
    }

    public Context getContext() {
        return context;
    }

    public void setContext(Context context) {
        this.context = context;
    }

    public FragmentManager getFragmentManager() {
        return fragmentManager;
    }

    public void setFragmentManager(FragmentManager fragmentManager) {
        this.fragmentManager = fragmentManager;
    }

    public Class<?> getmClass() {
        return mClass;
    }

    public void setmClass(Class<?> mClass) {
        this.mClass = mClass;
    }

    public String getContentText() {
        return contentText;
    }

    public void setContentText(String contentText) {
        this.contentText = contentText;
    }

    public String getOkText() {
        return okText;
    }

    public void setOkText(String okText) {
        this.okText = okText;
    }

    private String cancelText;


    public CommonDialog(BaseDialog dialog, Context context, FragmentManager fragmentManager, Class<?> mClass, String contentText, String okText, String cancelText) {
        this.dialog = dialog;
        this.context = context;
        this.fragmentManager = fragmentManager;
        this.mClass = mClass;
        this.contentText = contentText;
        this.okText = okText;
        this.cancelText = cancelText;
    }



    public void showDialog(){
        if(dialog ==null){
            dialog = new BaseDialog.Builder().
                    layResuorce(R.layout.dialog_common).
                    okViewClickEvent(R.id.tv_dialog_ok).
                    cancelViewClickEvent(R.id.tv_dialog_cancel).
                    gravityStyle(Gravity.CENTER).
                    animResource(R.style.dialog_animation_fade).
                    setContentText(contentText).
                    setOkText(okText).
                    setCancelText(cancelText).
                    dialogWidth(-2).
                    build();
            dialog.setOnDialogClickListener(new BaseDialog.OnDialogClickListener() {
                @Override
                public void onOkClick() {
                    Intent intent = new Intent(context,mClass);
                    context.startActivity(intent);
                    AppManager.getAppManager().finishActivity();
                    dialog.dismiss();
                }

                @Override
                public void onOk2Click() {

                }
            });
//            dialog.show(fragmentManager,"");
        }
    }

}
